package com.spring.config;

import com.spring.pojo.User;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.Date;

@ControllerAdvice
public class GlobalConfig {
    @ModelAttribute(value = "info")
    public User userInfo(){
        User user=new User();
        user.setId("sa-002");
        user.setPassword("1233");
        user.setName("zzc");
        user.setPublicationDate(new Date());
        return user;
    }
    @InitBinder("b")
    public void text1(WebDataBinder binder){
        binder.setFieldDefaultPrefix("b.");
    }
    @InitBinder("a")
    public void text2(WebDataBinder binder){
        binder.setFieldDefaultPrefix("a.");
    }
}
